f = open('p107_network.txt', 'r')

g = []
for line in f:
    line = line.replace('-', '0')
    line = line.split(',')
    g.append([int(num) for num in line])

n = len(g)
total = 0
edge = []
for i in xrange(n):
    for j in xrange(i + 1, n):
        total += g[i][j]
        if g[i][j]:
            edge.append((g[i][j], i, j))

edge.sort()
f = [i for i in xrange(n)]
def find(a, x):
    if a[x] == x:
        return x
    a[x] = find(a, a[x])
    return a[x]

for e in edge:
    w, x, y = e
    if find(f, x) != find(f, y):
        total -= w
        f[f[x]] = y

print total


